package org.sooth.utils;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {

     private static SessionFactory sessionFactory = null;

        public static void init(String cfg){
            try {
                sessionFactory = new Configuration().configure(cfg).buildSessionFactory();
            } catch (Throwable ex) {
                System.err.println("Initial SessionFactory creation failed." + ex);
                throw new ExceptionInInitializerError(ex);
            }
        }

        public static SessionFactory getSessionFactory() {
            return sessionFactory;
        }

        public static Session getSession(){
            return getSessionFactory().getCurrentSession();
        }
}
